package com.meilai.project.controller.web.personnel.attendance;

import com.meilai.project.dto.CommonResult;
import com.meilai.project.dto.personnel.attendance.OvertimeApplyDTO;
import com.meilai.project.service.personnel.attendance.OvertimeApplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(value = "web端加班流程审批控制器", description = "web端加班流程审批")
@RestController
@RequestMapping("api/web/overtime_apply")
public class WebOvertimeApplyController {

    @Autowired
    private OvertimeApplyService service;

    @GetMapping("list")
    @ApiOperation(value = "列表")
    public CommonResult list(@RequestParam(name = "page", defaultValue = "1") Integer page,
                             @RequestParam(name = "page_size", defaultValue = "10") Integer page_size) {
        return new CommonResult().success(service.selectPageList(page, page_size));
    }

    @GetMapping("checkList")
    @ApiOperation(value = "审核列表")
    public CommonResult check(@RequestParam(name = "page", defaultValue = "1") Integer page,
                              @RequestParam(name = "page_size", defaultValue = "10") Integer page_size) {
        return new CommonResult().success(service.checkPageList(page, page_size));
    }

    @PostMapping("save")
    @ApiOperation(value = "保存至草稿箱")
    public CommonResult save(@RequestBody OvertimeApplyDTO dto, @RequestParam(value = "wf_data_id", required = false) Long wf_data_id) {
        return new CommonResult().success(service.save(dto, wf_data_id, true));
    }

    @PostMapping("submit")
    @ApiOperation(value = "提交")
    public CommonResult submit(@RequestBody OvertimeApplyDTO dto, @RequestParam(value = "wf_data_id", required = false) Long wf_data_id) {
        return new CommonResult().success(service.submit(dto, wf_data_id));
    }

    @PostMapping("check")
    @ApiOperation(value = "审核")
    public CommonResult adopt(@RequestParam(value = "flow_id") Long flow_id,
                              @RequestParam(value = "isReturn") Boolean isReturn,
                              @RequestParam(value = "wf_data_id") Long wf_data_id,
                              @RequestParam(value = "opinion", required = false) String opinion) {
        return new CommonResult().success(service.check(flow_id, wf_data_id, isReturn, opinion));
    }

    @PostMapping("/remove")
    @ApiOperation("删除记录")
    public CommonResult remove(@RequestParam(value = "flow_id") Long flow_id, @RequestParam(value = "wf_data_id") Long wf_data_id) {
        return new CommonResult().success(service.remove(flow_id, wf_data_id));
    }

    @PostMapping("/actualDelete")
    @ApiOperation("彻底删除")
    public CommonResult actualDelete(@RequestParam(value = "flow_id") Long flow_id, @RequestParam(value = "wf_data_id") Long wf_data_id) {
        return new CommonResult().success(service.actualDelete(flow_id, wf_data_id));
    }

    @GetMapping("/one")
    @ApiOperation("获取信息")
    public CommonResult getDtoById(@RequestParam(value = "flow_id") Long flow_id) {
        return new CommonResult().success(service.getDtoById(flow_id));
    }
}
